package com.dexilaonian.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.dexilaonian.R;
import com.dexilaonian.adpter.ServiceDetailAdaprer;
import com.dexilaonian.adpter.StoreAdaprer;
import com.dexilaonian.adpter.StoreItemAdapter;
import com.dexilaonian.adpter.TabAdapter;
import com.dexilaonian.adpter.TextAdapter;
import com.dexilaonian.bean.PspecBean2;
import com.dexilaonian.ui.BaseActivity;
import com.dexilaonian.utils.Constant;
import com.dexilaonian.utils.ImageLoader;
import com.dexilaonian.utils.Logutil;
import com.dexilaonian.utils.Okhttp;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import bakerj.backgrounddarkpopupwindow.BackgroundDarkPopupWindow;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.onekeyshare.ShareContentCustomizeCallback;
import okhttp3.Call;

public class StoreDetailActivity extends BaseActivity implements View.OnClickListener {
    public static int POSITION = 0;
    @Bind(R.id.back)
    ImageView back;
    @Bind(R.id.xiangqin)
    TextView xiangqin;
    @Bind(R.id.rl)
    RelativeLayout rl;
    @Bind(R.id.store_viewpager)
    ViewPager storeViewpager;
    @Bind(R.id.tv_pro_price)
    TextView tvProPrice;
    @Bind(R.id.tv_yuna_price)
    TextView tvYunaPrice;

    @Bind(R.id.text_shou)
    TextView textShou;
    @Bind(R.id.rl_shou)
    RelativeLayout rlShou;
    @Bind(R.id.iv_shopping_trolley)
    ImageView ivShoppingTrolley;
    @Bind(R.id.store_shopping_trolley)
    Button storeShoppingTrolley;
    @Bind(R.id.store_shopping_buy)
    Button storeShoppingBuy;
    @Bind(R.id.shanpin)
    TextView shanpin;
    @Bind(R.id.fenxiang_xiangqi)
    ImageView fenxiangXiangqi;
    @Bind(R.id.viewpager_linerlayout)
    LinearLayout viewpagerLinerlayout;
    @Bind(R.id.ll_store1)
    LinearLayout llStore1;
    @Bind(R.id.iv_zhankai)
    ImageView ivZhankai;
    @Bind(R.id.changView)
    View changView;
    @Bind(R.id.title_listview)
    ListView titleListview;
    @Bind(R.id.text_listview)
    ListView textListview;
    @Bind(R.id.webview_detail)
    WebView webviewDetail;
    @Bind(R.id.trolley_num)
    TextView trolleyNum;

    @Bind(R.id.rl_shouqiyou)
    RelativeLayout rlShouqiyou;
    private List<String> storeList = new ArrayList<>();
    private ArrayList<PspecBean2> pspecBList = new ArrayList<>();
    private BackgroundDarkPopupWindow window;
    private String serviceuserid;
    private ServiceDetailAdaprer storeListDetail;
    private List<String> store_item_key = new ArrayList<>();
    private List<String> store_item_value = new ArrayList<>();
    private ArrayList<ImageView> mDots;
    private boolean isButtom = true;
    private long popNUM = 1;
    private String store_url = Constant.base_url + "/product/getDetailOfShopProduct";

    private List<String> tabList = new ArrayList<>();
    private List<String> TextList = new ArrayList<>();
    private String picUrl15;
    private String picUrl14;
    private String picUrl13;
    private String picUrl2;
    private String picUrl;
    private List<Map<String, Object>> data1;
    private int content_id;
    private int mPostion;
    private TextView myNum;
    private StoreItemAdapter storeItemAdapter;
    private String value;
    private TextView trolleyPrice;
    private TextView trolleyColor;
    private String price;
    private int cartcount;

    @Override
    public int getLayoutID() {
        return R.layout.activity_store_detail;
    }

    @Override
    public void initView() {

    }

    @Override
    protected void initData() {

    }
    private void initDetil(int content_id) {
        Map<String, String> detailMap = new HashMap<>();
        detailMap.put("productid", content_id + "");
        Okhttp.postString(false, store_url, detailMap, new Okhttp.CallBac() {
            @Override
            public void onError(Call call, Exception e, String state, int id) {

            }
            @Override
            public void onResponse(String response, int id) {
                Log.e("TTTSSS", response);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    int status = Integer.parseInt(jsonObject.optString("status"));
                    if (status == 34 || status == 16) {
                        startActivity(new Intent(StoreDetailActivity.this, LoginActivity.class));
                        return;
                    }
                    String data = jsonObject.optString("data");
                    JSONObject object = new JSONObject(data);
                    String originalPrice = object.optString("original_price");
                    price = object.optString("price");
                    tvYunaPrice.setText("￥" + originalPrice);
                    tvProPrice.setText("￥" + price);
                    String pSpec = object.optString("p_spec");
                    JSONObject jsonobject = new JSONObject(pSpec);
                    Iterator<String> iterator = jsonobject.keys();

                    while (iterator.hasNext()) {
                        String key = iterator.next();
                        String value = (String) jsonobject.get(key);
                        store_item_key.add(key);
                        store_item_value.add(value);
                        storeItemAdapter = new StoreItemAdapter(StoreDetailActivity.this, store_item_key);

                    }
                    String pInfo = object.optString("p_info");
                    JSONObject pinfo = new JSONObject(pInfo);
                    Iterator<String> iterator2 = pinfo.keys();
                    while (iterator2.hasNext()) {
                        String key2 = iterator2.next();
                        String value2 = (String) pinfo.get(key2);
                        tabList.add(key2);
                        TextList.add(value2);
                        TabAdapter tabAdapter = new TabAdapter(StoreDetailActivity.this, tabList);
                        titleListview.setAdapter(tabAdapter);
                        TextAdapter textAdapter = new TextAdapter(StoreDetailActivity.this, TextList);
                        textListview.setAdapter(textAdapter);
                    }
                    String name = object.optString("name");
                    picUrl15 = object.optString("pic_url5");
                    picUrl14 = object.optString("pic_url4");
                    picUrl13 = object.optString("pic_url3");
                    picUrl2 = object.optString("pic_url2");
                    picUrl = object.optString("pic_url");
                    storeList.add(picUrl15);
                    storeList.add(picUrl14);
                    storeList.add(picUrl13);
                    storeList.add(picUrl2);
                    storeList.add(picUrl);
                    initViewpager(storeList);
                    initDots();
                    init();
                    String pDetail = object.optString("p_detail");
                    Log.e("TTToriginalPrice==", originalPrice + "price==" + price + ",picUrl=" + picUrl + "  pDetail=" + pDetail);
                    webviewDetail.loadData(pDetail, "text/html", "UTF-8");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onNoNetwork(String state) {

            }
        });
    }

    private void initViewpager(List<String> storeList2) {
        // ArrayList<String> galleryPlusActivity = getIntent().getStringArrayListExtra("GalleryPlusActivity");
        data1 = getData((ArrayList<String>) storeList2);
        StoreAdaprer storeAdaprer = new StoreAdaprer(data1, StoreDetailActivity.this);
        storeViewpager.setAdapter(storeAdaprer);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);

        Intent intent = getIntent();
        if (intent != null) {
            Bundle extras = intent.getExtras();
            if (extras != null) {
                content_id = extras.getInt("content_id");
                Logutil.e("content_id =====" + content_id);
                initDetil(content_id);
            }
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        initGetCartNum();
    }

    private void initGetCartNum() {
        String cartNum_url = Constant.base_url + "/cart/count.do";
        Map<String, String> cartNum_map = new HashMap<>();
        Okhttp.postString(true, cartNum_url, cartNum_map, new Okhttp.CallBac() {
            @Override
            public void onError(Call call, Exception e, String state, int id) {
                showToast(state);
            }

            @Override
            public void onResponse(String response, int id) {
                Log.e("TTTTcartNum", response);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    int status = Integer.parseInt(jsonObject.optString("status"));
                    if (status == 0) {
                        int data = Integer.parseInt(jsonObject.optString("data"));
                        trolleyNum.setText(data + "");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onNoNetwork(String state) {
                showToast(state);
            }
        });
    }

    //这个方法长度是动态的，可以改成你从服务器获取的图片，这样数量就不确定啦
    public List<Map<String, Object>> getData(ArrayList<String> imageLists) {
        List<Map<String, Object>> mData = new ArrayList<>();

        if (imageLists != null && imageLists.size() > 0) {
            for (int i = 0; i < imageLists.size(); i++) {
                Map<String, Object> map = new HashMap<>();
                map.put("url", imageLists.get(i));
                map.put("view", new ImageView(this));
                mData.add(map);
            }
        }
        return mData;
    }

    private void initDots() {
        mDots = new ArrayList<ImageView>();//底部圆点集合的初始化
        for (int i = 0; i < data1.size(); i++) {//根据界面数量动态添加圆点
            ImageView imageView = new ImageView(this);
            imageView.setLayoutParams(new ViewGroup.LayoutParams(45, 45));//设置ImageView的宽度和高度
            imageView.setPadding(10, 10, 10, 10);//设置圆点的Padding，与周围的距离
            imageView.setImageResource(R.drawable.huiyuandian);//设置图片
            mDots.add(imageView);//将该图片添加到圆点集合中
            viewpagerLinerlayout.addView(imageView);//将图片添加到LinearLayout中
        }
        mDots.get(0).setImageResource(R.drawable.heiyuandian);
    }

    private void init() {
     /*   int[] store_pic = {R.drawable.beijing, R.drawable.beijing2, R.drawable.beijngse};
        for (int i = 0; i < store_pic.length; i++) {
            ImageView iv = new ImageView(this);
            iv.setBackgroundResource(store_pic[i]);
            storeList.add(iv);
        }*/
        // 把ViewPager设置为默认选中Integer.MAX_VALUE / 2，从十几亿次开始轮播图片，达到无限循环目的;
        // storeViewpager.setCurrentItem(currentPosition);
        storeViewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                for (int i = 0; i < data1.size(); i++) {
                    //将所有的圆点设置为为选中时候的图片
                    mDots.get(i).setImageResource(R.drawable.huiyuandian);
                }
                //将被选中的图片中的圆点设置为被选中的时候的图片
                mDots.get(position).setImageResource(R.drawable.heiyuandian);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @OnClick({R.id.fenxiang_xiangqi, R.id.rl_shouqiyou, R.id.back, R.id.rl_shou, R.id.iv_shopping_trolley, R.id.store_shopping_trolley, R.id.store_shopping_buy})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.fenxiang_xiangqi:
                showShare();
                break;
            case R.id.back:
                finish();
                break;
            case R.id.rl_shou:
                changView.setVisibility(View.VISIBLE);
                rl.setVisibility(View.VISIBLE);
                shanpin.setVisibility(View.VISIBLE);
                webviewDetail.setVisibility(View.VISIBLE);
                rlShou.setVisibility(View.GONE);
                rlShouqiyou.setVisibility(View.VISIBLE);
                break;
            case R.id.rl_shouqiyou:
                isButtom = true;
                changView.setVisibility(View.INVISIBLE);
                rl.setVisibility(View.INVISIBLE);
                shanpin.setVisibility(View.INVISIBLE);
                webviewDetail.setVisibility(View.GONE);
                rlShou.setVisibility(View.VISIBLE);
                rlShouqiyou.setVisibility(View.GONE);
                break;
            case R.id.iv_shopping_trolley:
                Intent intent = new Intent(StoreDetailActivity.this, ShoppingTrolleyActivity.class);
                startActivity(intent);
                break;
            case R.id.store_shopping_trolley:
                mPostion = 0;
                doctor_poWindow();
                break;
            case R.id.store_shopping_buy:
                mPostion = 1;
                doctor_poWindow();
                break;
        }
    }

    private void initGetTrolley() {
        String num = myNum.getText().toString().trim();
        showProgressBar(true);
        String trolley_url = Constant.base_url + "/cart/save_cart.do";
        Map<String, String> trolley_map = new HashMap<>();
        trolley_map.put("productid", content_id + "");
        trolley_map.put("quantity", num);
        trolley_map.put("pspec", value);
        Okhttp.postString(true, trolley_url, trolley_map, new Okhttp.CallBac() {
            @Override
            public void onError(Call call, Exception e, String state, int id) {
                showProgressBar(false);
                showToast(state);
            }

            @Override
            public void onResponse(String response, int id) {
                Log.e("TTTTROLLEY", response);
                showProgressBar(false);
                try {
                    JSONObject jsonObject = new JSONObject(response);
                    int status = Integer.parseInt(jsonObject.optString("status"));
                    if (status == 34 || status == 16) {
                        startActivity(new Intent(StoreDetailActivity.this, LoginActivity.class));
                        return;
                    }
                    if (status == 0) {
                        showToast("加入购物车成功");
                        String data = jsonObject.optString("data");
                        if (!data.equals("null")) {
                            Log.e("TTT", data);
                        }
                        if (data != null) {
                            Log.e("TTT22", data);

                            JSONObject object = new JSONObject(data);
                            cartcount = Integer.parseInt(object.optString("cartCount"));
                          //  trolleyNum.setVisibility(View.VISIBLE);
                            trolleyNum.setText(cartcount + "");
                            window.dismiss();
                        } else {
                            trolleyNum.setVisibility(View.GONE);
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public void onNoNetwork(String state) {
                showProgressBar(false);
                showToast(state);
            }
        });
    }

    private void showShare() {
        OnekeyShare oks = new OnekeyShare();
        /*oks.addHiddenPlatform(QQ.NAME);
        oks.setImageData();*/
        //关闭sso授权
        oks.disableSSOWhenAuthorize();
        oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {
            @Override
            public void onShare(Platform platform, Platform.ShareParams paramsToShare) {
                if ("SinaWeibo".equals(platform.getName())) {
                    paramsToShare.setText("我是文本,分享链接通过拼接文本方式分享链接" + "http://sharesdk.cn");
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png ");
                    /*paramsToShare.setFilePath(ResourcesManager.getInstace(MobSDK.getContext()).getFilePath());*/
                   /* paramsToShare.setUrl("http://sharesdk.cn");*/
                }
                if ("Wechat".equals(platform.getName())) {
                    paramsToShare.setTitle("标题");
                    paramsToShare.setUrl("http://sharesdk.cn");
                    paramsToShare.setText("我是共用的参数，这几个平台都有text参数要求，提取出来啦");
                    /*paramsToShare.setW*/
                    /*Bitmap imageData = BitmapFactory.decodeResource(getResources(), R.drawable.ssdk_logo);
                    paramsToShare.setImageData(imageData);*/
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png ");
                    paramsToShare.setShareType(Platform.SHARE_WEBPAGE);
                }

                if ("WechatMoments".equals(platform.getName())) {
                    paramsToShare.setTitle("标题");
                    paramsToShare.setUrl("http://sharesdk.cn ");
                    paramsToShare.setText("我是共用的参数，这几个平台都有text参数要求，提取出来啦");
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png ");
                    paramsToShare.setShareType(Platform.SHARE_WEBPAGE);
                }
                if ("QQ".equals(platform.getName())) {
                    paramsToShare.setTitle("标题");
                    paramsToShare.setTitleUrl("http://sharesdk.cn");
                    paramsToShare.setText("我是共用的参数，这几个平台都有text参数要求，提取出来啦");
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png");
                }
                if ("Facebook".equals(platform.getName())) {
                    //Facebook空间您自己写了
                    paramsToShare.setText("我是共用的参数，这几个平台都有text参数要求，提取出来啦");
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png");
                }
                if ("QZone".equals(platform.getName())) {
                    //QQ空间您自己写了
                    paramsToShare.setTitle("标题");
                    paramsToShare.setTitleUrl("http://sharesdk.cn");
                    paramsToShare.setText("我是共用的参数，这几个平台都有text参数要求，提取出来啦");
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png");
                }
                if ("Alipay".equals(platform.getName())) {
                    paramsToShare.setTitle("标题");
                    paramsToShare.setUrl("http://sharesdk.cn");
                    paramsToShare.setText("我是共用的参数，这几个平台都有text参数要求，提取出来啦");
                    /*Bitmap imageData = BitmapFactory.decodeResource(getResources(), R.drawable.ssdk_logo);
                    paramsToShare.setImageData(imageData);*/
                    paramsToShare.setImageUrl("https://hmls.hfbank.com.cn/hfapp-api/9.png");
                    paramsToShare.setShareType(Platform.SHARE_WEBPAGE);
                }
            }
        });
        oks.setCallback(new PlatformActionListener() {
            @Override
            public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {
                // fenxiangTop.setImageDrawable(getResources().getDrawable(R.drawable.fenxiang));
                Toast.makeText(StoreDetailActivity.this, "分享成功", Toast.LENGTH_SHORT).show();
                platform.getName();
            }

            @Override
            public void onError(Platform platform, int i, Throwable throwable) {
                Toast.makeText(StoreDetailActivity.this, "分享失败", Toast.LENGTH_SHORT).show();
                throwable.printStackTrace();
            }

            @Override
            public void onCancel(Platform platform, int i) {
                Toast.makeText(StoreDetailActivity.this, "分享取消", Toast.LENGTH_SHORT).show();
            }
        });
// 启动分享GUI
        oks.show(this);
    }

    /**
     * 显示popupWindow
     */
    private void doctor_poWindow() {
        // 利用layoutInflater获得View
        final LayoutInflater inflater = (LayoutInflater) getSystemService(Context
                .LAYOUT_INFLATER_SERVICE);
        View view = inflater.inflate(R.layout.item_type, null);
        window = new BackgroundDarkPopupWindow(view,
                WindowManager.LayoutParams.MATCH_PARENT,
                1100);
        ImageView popJia = (ImageView) view.findViewById(R.id.pop_jia);
        ImageView popJian = (ImageView) view.findViewById(R.id.pop_jian);
        ImageView storePic = (ImageView) view.findViewById(R.id.item_store_pic);
        trolleyPrice = (TextView) view.findViewById(R.id.item_trolley_price);
        trolleyColor = (TextView) view.findViewById(R.id.item_trolley_color);

        value = store_item_value.get(0);
        trolleyPrice.setText("￥"+price);
        trolleyColor.setText(value);
        if (!TextUtils.isEmpty(picUrl15)) {
            ImageLoader.display(StoreDetailActivity.this,picUrl15,storePic);
        }
        GridView grid_guige = (GridView) view.findViewById(R.id.grid_storeItem);
        grid_guige.setAdapter(storeItemAdapter);
        grid_guige.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                POSITION = position;
                value = store_item_value.get(position);
                trolleyPrice.setText("￥"+price);
                trolleyColor.setText(value);
                storeItemAdapter.notifyDataSetChanged();
            }
        });
        myNum = (TextView) view.findViewById(R.id.pop_num);
        myNum.setText(1 + "");
        ImageView quxiao = (ImageView) view.findViewById(R.id.quxiao_type);
        Button btyType = (Button) view.findViewById(R.id.btn_type);
        // 下面是两种方法得到宽度和高度 getWindow().getDecorView().getWidth()

        window.setSoftInputMode(PopupWindow.INPUT_METHOD_NEEDED);
        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        // 设置popWindow弹出窗体可点击，这句话必须添加，并且是true
        window.setFocusable(true);
        window.setDarkStyle(-1);
        window.resetDarkPosition();
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        window.setBackgroundDrawable(dw);
        window.setBackgroundDrawable(getResources().getDrawable(R.color.colorpopuwindow));
        // 设置popWindow的显示和消失动画
        window.setAnimationStyle(R.style.mypopwindow_anim_style);
        // 在底部显示
        window.showAtLocation(StoreDetailActivity.this.findViewById(R.id.tv_pro_price),
                Gravity.BOTTOM, 0, 0);
        quxiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                window.dismiss();
            }
        });
        btyType.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mPostion == 0) {
                    initGetTrolley();
                    window.dismiss();
                } else if (mPostion == 1) {
                    String num2 = myNum.getText().toString().trim();
                    Intent intent = new Intent(StoreDetailActivity.this, ConfirmStoreActivity.class);

                  /*  com.alibaba.fastjson.JSONObject  jsonObject = new com.alibaba.fastjson.JSONObject();
                    com.alibaba.fastjson.JSONArray jsonArray = new com.alibaba.fastjson.JSONArray();
                    try {
                        jsonObject.put("productId",content_id);
                        jsonObject.put("quantity", Integer.parseInt(num2));
                        jsonObject.put("pspec", value);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    jsonArray.add(jsonObject);
                    Log.e("TTTjsonArray22", jsonArray.toString());*/
                 // intent.putExtra("JSONARRAY", jsonArray.toJSONString());
                    intent.putExtra("CONFIRMS", "CONFIRMS");
                    intent.putExtra("productId", content_id);
                    intent.putExtra("quantity", Integer.parseInt(num2));
                    intent.putExtra("pspec", value);
                    startActivity(intent);
                    window.dismiss();
                }
            }
        });
        popJia.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popNUM++;
                myNum.setText(popNUM + "");
            }
        });
        popJian.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popNUM--;
                if (popNUM < 1) {
                    Toast.makeText(StoreDetailActivity.this, "该宝贝不能减少了哟~", Toast.LENGTH_SHORT).show();
                    popNUM = 1;
                    return;
                }
                myNum.setText(popNUM + "");
            }
        });
        //popWindow消失监听方法
        window.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {

            }
        });
    }
}
